<template>
  <view>
    <up-tabbar
      :value="pathValue"
      :safeAreaInsetBottom="true"
      :fixed="true"
      :placeholder="true"
      activeColor="#f9560a"
    >
      <up-tabbar-item
        text="首页"
        @click="goto('/pages/index/index')"
        icon="home"
      >
      </up-tabbar-item>
      <up-tabbar-item
        text="提醒"
        icon="photo"
        @click="goto('/pages/reminder/reminder')"
      ></up-tabbar-item>
      <up-tabbar-item
        text="运动圈"
        icon="play-right"
        @click="goto('/pages/exercise/exercise')"
      ></up-tabbar-item>
      <up-tabbar-item
        text="我的"
        icon="account"
        @click="goto('/pages/me/me')"
      ></up-tabbar-item>
    </up-tabbar>
  </view>
</template>

<script setup>
import { onMounted, ref, watch } from "vue";

const pathValue = ref(0);
const goto = (path) => {
  // if (path === "/pages/index/index") {
  //   pathValue.value = 0;
  // } else if (path === "/pages/reminder/reminder") {
  //   pathValue.value = 1;
  // } else if (path === "/pages/exercise/exercise") {
  //   pathValue.value = 2;
  // }
  // if (path === "/pages/me/me") {
  //   pathValue.value = 3;
  // }
  uni.switchTab({
    url: path,
  });
};
const pages = getCurrentPages(); // 获取页面栈
const currentPage = pages[pages.length - 1]; // 获取当前页面
// 获取当前页面的路径
let path = currentPage.route;
if (path === "pages/index/index") {
  pathValue.value = 0;
} else if (path === "pages/reminder/reminder") {
  pathValue.value = 1;
} else if (path === "pages/exercise/exercise") {
  pathValue.value = 2;
}
if (path === "pages/me/me") {
  pathValue.value = 3;
}
</script>

<style></style>
